<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>随手快递</title>
	<link rel="stylesheet" type="text/css" href="../../AUI/css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../../font-awesome/css/font-awesome.min.css" />
	<link rel="stylesheet" href="../../myCss/LArea.css">
	<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
	<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=a37424dd342449fb8ab5f809081e01ce&plugin=AMap.Geocoder"></script>
	<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
	<style type="text/css">
		.aui-content {
			margin-top: 45px;
		}
		.aui-list-item-label,.aui-list-item-input input[type="text"]{
			font-size: 14px;
		}
		.aui-list{
			width: 100%;
		}
		.aui-list .aui-list-item .addr{
			padding-left: 0;
		}
		textarea{
			font-size: 14px;
		}
	</style>
</head>
<body style="overflow-x: hidden" >
<header class="aui-bar aui-bar-nav" id="aui-header">
	<a class="aui-btn aui-pull-left" tapmode onclick="history.back();">
		<span class="aui-iconfont aui-icon-left"></span>
	</a>
	<div class="aui-title">添加新地址</div>
	<div class="aui-btn aui-pull-right" id="save"><small>保存</small></div>
</header>
<div class="aui-content aui-margin-b-15">
	<ul class="aui-list aui-form-list">
		<li class="aui-list-item aui-border-b">
			<div class="aui-list-item-inner">
				<div class="aui-list-item-label">
					收件人
				</div>
				<div class="aui-list-item-input">
					<input type="text" placeholder="" id="contacts">
				</div>
			</div>
		</li>
		<li class="aui-list-item aui-border-b">
			<div class="aui-list-item-inner">
				<div class="aui-list-item-label">
					联系方式
				</div>
				<div class="aui-list-item-input">
					<input type="text" placeholder="" id="contactsPhone">
				</div>
			</div>
		</li>
		<li class="aui-list-item aui-border-b">
			<div class="aui-list-item-inner">
				<div class="aui-list-item-label">
					所在地区
				</div>
				<div class="aui-list-item-input aui-list-item-arrow">
					<div class="content-block">
						<input id="address" type="text" readonly  placeholder="请选择"/>
						<input id="value2" type="hidden" />
					</div>
				</div>
			</div>
		</li>
		<li class="aui-list-item">
			<ul class="aui-list">
				<li class="aui-list-item addr">
					<div class="aui-list-item-input"><textarea id="address1" placeholder="请填写详细地址，不少于5个字"></textarea>
					</div>
				</li>
			</ul>
		</li>
	</ul>
</div>
<div style="display: none;">
<div id="container" style="height: 200px;top:270px"></div>
<div id="tip"><span id="result"></span>
</div>
</div>
<script type="text/javascript" src="../../myJs/jquery-1.12.1.min.js" ></script>
<script src="../../myJs/jquery.cookie.js"></script>
<script src="../../myJs/LAreaData1.js"></script>
<script src="../../myJs/LAreaData2.js"></script>
<script src="../../myJs/LArea.js"></script>
<script>
	var loc,addressLongitude,addressLatitude,address1;
	var contacts ;
	var contactsPhone;
	var address;
	//保存地址
	$("#save").on("click",function(){
		contacts = $("#contacts").val();
		contactsPhone = $("#contactsPhone").val();
		address = $("#address").val();
		address1 = $("#address1").val();
		loc = address+address1;
		geocoder();

	})
	var map = new AMap.Map("container", {
		resizeEnable: true
	});
	function geocoder() {
		var geocoder = new AMap.Geocoder({
		});
		//地理编码,返回地理编码结果
		geocoder.getLocation(loc, function(status, result) {

			addressLongitude = result.geocodes[0].location.lng;
			addressLatitude = result.geocodes[0].location.lat;
			console.log(address+address1+contacts+contactsPhone+addressLongitude+addressLatitude);
			alert(address1);
			$.ajax({
			 type: "post",
			 url: '/randomdelivery/userManageController/addAddress',
			 data: {
			 "address": address,
			 "addressDetails": address1,
			 "contacts": contacts,
			 "contactsPhone": contactsPhone,
			 "addressLongitude":addressLongitude,
			 "addressLatitude":addressLatitude
			 },
			 datatype: "json",
			 success: function (data) {
			 location.href="address.html";
			 }

			 });
			/*if (status === 'complete' && result.info === 'OK') {
				geocoder_CallBack(result);
			}*/
		});
	}
	/*function addMarker(i, d) {
		var marker = new AMap.Marker({
			map: map,
			position: [ d.location.getLng(),  d.location.getLat()]
		});
		var infoWindow = new AMap.InfoWindow({
			content: d.formattedAddress,
			offset: {x: 0, y: -30}
		});
		marker.on("mouseover", function(e) {
			infoWindow.open(map, marker.getPosition());
		});
	}
	//地理编码返回结果展示
	function geocoder_CallBack(data) {
		var resultStr = "";
		//地理编码结果数组
		var geocode = data.geocodes;
		for (var i = 0; i < geocode.length; i++) {
			//拼接输出html
			resultStr += "<span style=\"font-size: 12px;padding:0px 0 4px 2px; border-bottom:1px solid #C1FFC1;\">" + "<b>地址</b>：" + geocode[i].formattedAddress + "" + "&nbsp;&nbsp;<b>的地理编码结果是:</b><b>&nbsp;&nbsp;&nbsp;&nbsp;坐标</b>：" + geocode[i].location.getLng() + ", " + geocode[i].location.getLat() + "" + "<b>&nbsp;&nbsp;&nbsp;&nbsp;匹配级别</b>：" + geocode[i].level + "</span>";
			addMarker(i, geocode[i]);
			lng = geocode[i].location.getLng();
			alert(lng);
			//sessionStorage.setItem("lng",lng);
			lat = geocode[i].location.getLat();
		}
		map.setFitView();
		document.getElementById("result").innerHTML = resultStr;
	}*/


	var area2 = new LArea();
	area2.init({
		'trigger': '#address',
		'valueTo': '#value2',
		'keys': {
			id: 'value',
			name: 'text'
		},
		'type': 2,
		'data': [provs_data, citys_data, dists_data]
	});


</script>
</body>
</html>